import os
from PIL import Image


def resize_pics(dir_path=r'G:/python-files/resize_pics/test_pics/',
                out_path=r'G:/python-files/resize_pics/res_pics/%s',
                ratio=0.25):
    """
    帮助老妈批量修改图片大小
    :param dir_path: 图像文件存放路径
    :param out_path: 压缩图像输出路径
    :param ratio: 等比压缩比例
    :return:
    """
    all_file = os.listdir(dir_path)
    for i in all_file:
        file = dir_path + i
        img = Image.open(file)
        w, h = img.size

        new_width = int(w * ratio)
        new_height = int(h * ratio)

        img = img.resize((new_width, new_height), Image.ANTIALIAS)
        img.save(out_path % i, optimize=True, quality=85)


if __name__ == "__main__":
    resize_pics()